<!-- Dialog Box to Place Bet & Challenge (with match and challenge details) -->
<%match = Match.find(sid)%>
<%match_not_placed =  !(@user||current_user).bets.map{|b| b.match_id}.include?(sid.to_i)%>

<form id="dialog_form" action='<%=bets_url%>' method='post'>
    <!--ch have exist , accept challenge and place bet etc-->
     <%if (ch rescue false)%>
        <table>
	        <tr>
				<td class='dialog-text'>From:</td><td> <%=ch.sender.name%> </td> 
			</tr>
	        <%if match_not_placed%>
				<tr>
					<td class='dialog-text'>Your bet:</td>
					<td>
						<input type=hidden name="bet[][match_id]" value="<%=sid%>">
						<input type=radio name=bet[][team_id] value=<%=match.home_team.id%> checked> <%=match.home_team.displayed_name%><br/>
						<input type=radio name=bet[][team_id] value=<%=match.away_team.id%>> <%=match.away_team.displayed_name%>
					</td>
				</tr>
	        <%else%>
				<tr>
					<td class='dialog-text'>Your bet:</td><td><%=current_user.bet(match).team.displayed_name%>
					</td>
				</tr>
			<%end%>
			<tr>
				<td class='dialog-text'>
					<%=ch.sender.name%>'s bet:
				</td>
				<td>
					<%=ch.sender.bet(match).team.displayed_name%>
				</td>
			</tr>
			<tr>
				<td class='dialog-text'>
					Handicap:
				</td>
				<td>
					<%= "#{(match.point_spread > 0 ? "Home team favored to win by " : "Away team favored to win by ") + match.point_spread.to_f.abs.to_s}" + " points" %>
				</td>
			</tr>
	        <tr>
				<td class='dialog-text'>Amount:</td>
		        <td> 
					<%=ch.amount%> WinPoints
					<input type=hidden name="sid" value="<%=sid%>">
					<input type=hidden name="chid" value="<%=ch.id%>">
				</td>
			</tr>
	        <tr>
				<td colspan=2 class='dialog-text'>Message:<br/><p></p>
					<%=ch.message%>
				</td>
			</tr>
        </table>
	   
    <!-- ch not exist -->
    <%else%>
        <table>
			<tr>
				<td class='dialog-text'>
					To:
				</td>
				<td>
					<%if u%>
						<%=u.name%>
						<input type=hidden name="to_user_id" value="<%=u.id%>">
					<%else%>
						<select name="to_user_id">
							<%=options_from_collection_for_select (@other_friends||current_user.other_friends(sid)),:id,:name%>
						</select>
					<%end%>
				</td>
			</tr>
			<%if u%>
				<tr>
					<td class='dialog-text'>His/her bet:</td>
					<td>
						<%=u.bet(match).team.displayed_name%>
					</td>
				</tr>
			<%end%>
	       <%if match_not_placed%>
				<tr>
				   <td class='dialog-text'>Your bet:</td>
				   <td>
					  <input type=hidden name="bet[][match_id]" value="<%=sid%>">
					  <input type=radio name=bet[][team_id] value=<%=match.home_team.id%> checked> <%=match.home_team.displayed_name%><br/>
					  <input type=radio name=bet[][team_id] value=<%=match.away_team.id%>> <%=match.away_team.displayed_name %>
				   </td>
			   </tr>
			<%else%>
				<tr>
					<td class='dialog-text'>Your bet:</td><td>team <%=current_user.bet(match).team.displayed_name%></td>
				</tr>
			<%end%>
			<tr>
				<td class='dialog-text'>
					Handicap:
				</td>
				<td>
					<%= "#{(match.point_spread > 0 ? "Home team favored to win by " : "Away team favored to win by ") + match.point_spread.to_f.abs.to_s}" + " points" %>
				</td>
			</tr>
			<tr>
				<td class='dialog-text'>
					Amount:
				</td>
					<td> 
						<input type=text style="width:30px" name="amount" value=100> WinPoints<span class='dialog-text'> (max. 500)</span>
						<input type=hidden name="sid" value="<%=sid%>">
						<input type=hidden name="sport_id" value="<%=match.sport_id%>">
					</td>
			</tr>
			<tr>
				<td colspan=2 class='dialog-text'>Message:<br/><p></p>
					<textarea name="message" style="width:410px;height:40px;">You will not beat me!</textarea>
			   </td>
	       </tr>
		</table>
	<%end%>
	<p></p>
</form>

